#include "../../src/thread/Event.h"
#include "../../src/thread/Thread.h"
#include "../../src/time/Time.h"
#include "../test_type.h"
#include "../dump/dump.h"
#include <iostream>
#include <cstdio>

using namespace LibTools;
using namespace std;

DWORD Func(void *invoker)
{
	CEventBase* event = (CEventBase*) invoker;

	ShareApi::Sleep(2000);
	event->SetEvent(true);

	return 0;
}

#define EVENT_COUNT 10

#ifdef TEST_EVENT
int main()
{
	CDump::SetDumpOpen();

	vector<CEventBase*> ves;
	CEvent e[EVENT_COUNT];
	CThread t[EVENT_COUNT];
	wt_status s;

	for (int i = 0; i < EVENT_COUNT; i++)
	{
		ves.push_back(&e[i]);
		t[i].Start(&Func, ves[i]);
	}

	cout << "wait all events time:" << CTimeTools::GetTimeStr() << endl;
	CWaitMultiEventForever w(ves, true, s);
	cout << "all events exit time:" << CTimeTools::GetTimeStr() << endl;

	for (int i = 0; i < EVENT_COUNT; i++)
	{
		t[i].Join();
	}

	getchar();

	return 0;
}
#endif // TEST_EVENT